package com.hh.us.conf;

import java.io.IOException;
import java.util.Properties;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

@Component
public class DomainConf {
	private static final Logger LOGGER = LoggerFactory
			.getLogger(DomainConf.class);
	private static final String CONF_PATH = "conf/domain.properties";

	private String basepath;

	@PostConstruct
	public void init() {
		try {
			LOGGER.info("load doamin config file from {}", CONF_PATH);
			Properties properties = PropertiesLoaderUtils
					.loadAllProperties(CONF_PATH);
			String bp = (String) properties.get("basepath");
			if(StringUtils.isNotBlank(bp)) {
				setBasepath(bp);
			} else {
				LOGGER.warn("load domain file success, but not found basepath value.");
			}
		} catch (IOException e) {
			LOGGER.warn(
					"load doamin config file failed. config file path:{}. msg:{}",
					CONF_PATH, e.getMessage(), e);
		}

	}

	public String getBasepath() {
		return basepath;
	}

	public void setBasepath(String basepath) {
		LOGGER.info("set basepath to {}", basepath);
		this.basepath = basepath;
	}

}
